home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 31 / Amiga Format CD31 (1998-09-02)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1998-10].iso / -seriously_amiga- / hardware / transadf / source / td.c < prev    next >
C/C++ Source or Header  |  1998-07-20  |  3KB  |  100 lines

  1. /* td.c - Handle all TrackDisk related tasks
  2. ** Copyright (C) 1997,1998 Karl J. Ots
  3. ** 
  4. ** This program is free software; you can redistribute it and/or modify
  5. ** it under the terms of the GNU General Public License as published by
  6. ** the Free Software Foundation; either version 2 of the License, or
  7. ** (at your option) any later version.
  8. ** 
  9. ** This program is distributed in the hope that it will be useful,
  10. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ** GNU General Public License for more details.
  13. ** 
  14. ** You should have received a copy of the GNU General Public License
  15. ** along with this program; if not, write to the Free Software
  16. ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  17. */
  18.  
  19. /*--------------------*/
  20. /* TrackDisk Routines */
  21. /*--------------------*/
  22.  
  23. #include <exec/types.h>
  24. #include <exec/io.h>
  25. #include <devices/trackdisk.h>
  26. #include <clib/exec_protos.h>
  27.  
  28. #include "td.h"
  29.  
  30.  
  31. /* Private functions */
  32. BYTE rwTrack (APTR  Buffer, UBYTE NumTracks, UBYTE TrackNum, 
  33.               struct IOExtTD *DiskReq);
  34.  
  35.  
  36. /* 
  37. ** Read a number of complete tracks from a specified unit.
  38. ** Return DoIO()'s return value.
  39. */
  40. BYTE readTrack (APTR   rBuffer,
  41.                 UBYTE  rNumTracks,
  42.                 UBYTE  rTrackNum,
  43.                 struct IOExtTD *rDiskReq)
  44. {
  45.   /* Read from track */
  46.   rDiskReq->iotd_Req.io_Command = ETD_READ;
  47.   return rwTrack (rBuffer, rNumTracks, rTrackNum, rDiskReq);
  48. }
  49.  
  50.  
  51. /*
  52. ** Write a number of complete tracks to a specified unit with TD_FORMAT.
  53. ** Return DoIO()'s return value.
  54. */
  55. BYTE writeTrack (APTR   wBuffer,
  56.                  UBYTE  wNumTracks,
  57.                  UBYTE  wTrackNum,
  58.                  struct IOExtTD *wDiskReq)
  59. {
  60.   BYTE TDError;
  61.   
  62.   /* First format the track */
  63.   wDiskReq->iotd_Req.io_Command = ETD_FORMAT;
  64.   TDError = rwTrack (wBuffer, wNumTracks, wTrackNum, wDiskReq);
  65.   if (TDError) return TDError;
  66.  
  67.   /* Write to the track */
  68.   wDiskReq->iotd_Req.io_Command = ETD_WRITE;
  69.   return rwTrack (wBuffer, wNumTracks, wTrackNum, wDiskReq);
  70. }
  71.  
  72.  
  73. /*
  74. ** Perform track-sized IO on specified unit.
  75. ** Return DoIO()'s return value.
  76. */
  77. BYTE rwTrack (APTR  Buffer,
  78.               UBYTE NumTracks,
  79.               UBYTE TrackNum,
  80.               struct IOExtTD *DiskReq)
  81. {
  82.   DiskReq->iotd_Req.io_Flags   = 0;
  83.   DiskReq->iotd_Req.io_Data    = Buffer;
  84.   DiskReq->iotd_Req.io_Length  = NumTracks * TRACK_SIZE;
  85.   DiskReq->iotd_Req.io_Offset  = TrackNum  * TRACK_SIZE;
  86.   DiskReq->iotd_SecLabel       = NULL;
  87.   
  88.   return DoIO ((struct IORequest *)DiskReq);
  89. }
  90.  
  91. /*
  92. ** Flush the track buffer on the specified unit.
  93. ** Return DoIO()'s return value.
  94. */
  95. BYTE flushTrack (struct IOExtTD *DiskReq)
  96. {
  97.   DiskReq->iotd_Req.io_Command = ETD_UPDATE;
  98.   return DoIO ((struct IORequest *)DiskReq);
  99. }
  100.